<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key=AIzaSyCJvUMzxhM4LLURlG3e1MwUkR09YSkUiBI" type="text/javascript"></script>
<?php 
echo $javascript->codeBlock("

				var sherhMap = {
					init: function(tapMapID){
						if (GBrowserIsCompatible()) {
							sherhMap.obiekt = tapMapID;
							sherhMap.map[sherhMap.obiekt] = new GMap2(document.getElementById(\"map_\"+sherhMap.obiekt));
							sherhMap.map[sherhMap.obiekt].addControl(new GSmallMapControl());
							sherhMap.map[sherhMap.obiekt].addControl(new GMapTypeControl());
							this.setcenter();
							this.geocoder = new GClientGeocoder();
							this.marker = new GMarker(this.center, {draggable: true});
							sherhMap.map[sherhMap.obiekt].addOverlay(sherhMap.marker);
							var pt = sherhMap.marker.getPoint();
							this.resultCoord(this.center.lat(),this.center.lng(),pt);
							sherhMap.addListnerMarker();
							sherhMap.addListnerMap();			
						}
					},
					mapID: false,
					obiekt: false,
					map: {},
					lat: ".$latitude.",
					lng: ".$longitude.",
					zoom: 11,
					center: false,
					setcenter: function(){
						this.center = new GLatLng(this.lat,this.lng);
						this.map[sherhMap.obiekt].setCenter(this.center, this.zoom);
					},
					geocoder: false,
					marker: false,
					point: false,
					addListnerMarker: function(){
						GEvent.addListener(sherhMap.marker, \"dragend\", function() {
							sherhMap.point = sherhMap.marker.getPoint();
							sherhMap.map[sherhMap.obiekt].panTo(sherhMap.point);
							sherhMap.resultCoord(sherhMap.point.lat(),sherhMap.point.lng(),sherhMap.point);
						});	
					},
					addListnerMap: function(){
						GEvent.addListener(sherhMap.map[sherhMap.obiekt], \"moveend\", function() {
							sherhMap.map[sherhMap.obiekt].clearOverlays();
							sherhMap.center = sherhMap.map[sherhMap.obiekt].getCenter();
							sherhMap.marker = new GMarker(sherhMap.center, {draggable: true});
							sherhMap.map[sherhMap.obiekt].addOverlay(sherhMap.marker);
							var pt = sherhMap.marker.getPoint();
							sherhMap.resultCoord(sherhMap.center.lat(),sherhMap.center.lng(),pt);
			
							GEvent.addListener(sherhMap.marker, \"dragend\", function() {
								sherhMap.point = sherhMap.marker.getPoint();
								sherhMap.map[sherhMap.obiekt].panTo(sherhMap.point);
								sherhMap.resultCoord(sherhMap.point.lat(),sherhMap.point.lng(),sherhMap.point);
							});
						});	
					},
					resultCoord: function(lat,lng,pt){
						//$(\"lat\"+sherhMap.obiekt).attr(\"value\",lat);
						//$(\"lng\"+sherhMap.obiekt).attr(\"value\",lng);
						document.getElementById(\"lat\"+this.obiekt).value = lat;
						document.getElementById(\"lng\"+this.obiekt).value = lng;
						sherhMap.addressGPS(pt);
					},
					addressGPS: function (point){
						var latA = Math.abs(Math.round(value=point.y * 1000000.));
						var lonA = Math.abs(Math.round(value=point.x * 1000000.));

						if(value=point.y < 0){
							var ls = '-' + Math.floor((latA / 1000000));
						}else{
							var ls = Math.floor((latA / 1000000));
						}

						var lm = Math.floor(((latA/1000000) - Math.floor(latA/1000000)) * 60);
						var ld = ( Math.floor(((((latA/1000000) - Math.floor(latA/1000000)) * 60) - Math.floor(((latA/1000000) - Math.floor(latA/1000000)) * 60)) * 100000) *60/100000 );

						if(value=point.x < 0){
  							var lgs = '-' + Math.floor((lonA / 1000000));
						}else{
							var lgs = Math.floor((lonA / 1000000));
						}

						var lgm = Math.floor(((lonA/1000000) - Math.floor(lonA/1000000)) * 60);
						var lgd = ( Math.floor(((((lonA/1000000) - Math.floor(lonA/1000000)) * 60) - Math.floor(((lonA/1000000) - Math.floor(lonA/1000000)) * 60)) * 100000) *60/100000 );

						//Use: + for N Lat or E Long     - for S Lat or W Long.
						//alert('Latitude '+ ld + (ld<0)?'S ':'N ' + lm + '\'' + ls +'\"');
						//alert('Longitude '+ lgd + (lgd<0)?'W ':'E ' + lgm + '\'' + lgs +'\"');
						
						document.getElementById('gps-ID-').value = ((ld<0)?'S ':'N ') + ld.toFixed(1) +'° '+  lm + '\' ' + ls +'\" ' +  ((lgd<0)?'W ':'E ') + lgd.toFixed(1) + '° ' + lgm + '\' ' + lgs +'\" ';
						
						//document.getElementById('latboxm').value=ls;
						//document.getElementById('latboxmd').value=lm;
						//document.getElementById('latboxms').value=ld;
						
						//document.getElementById('lonboxm').value=lgs;
						//document.getElementById('lonboxmd').value=lgm;
						//document.getElementById('lonboxms').value=lgd;
					},

					showAddress: function (id) {
						address = $(\"#selectedAdressArea\"+id).text() + $(\"#tapAdres\"+id).val();
						if (sherhMap.geocoder) {
							
							sherhMap.geocoder.getLatLng(address,	function( point ) {
								if (!point) {
									alert(address + \" not found\");
								} else {
									sherhMap.resultCoord(point.lat(),point.lng(),point);
									sherhMap.map[id].clearOverlays()
									sherhMap.map[id].setCenter(point, sherhMap.zoom);
									sherhMap.marker = new GMarker(point, {draggable: true});  
									sherhMap.map[id].addOverlay(sherhMap.marker);
					
									GEvent.addListener(sherhMap.marker, \"dragend\", function() {
										var pt = sherhMap.marker.getPoint();
										sherhMap.map[id].panTo(pt);
										document.getElementById(\"lat\"+sherhMap.obiekt).value = pt.lat();
										document.getElementById(\"lng\"+sherhMap.obiekt).value = pt.lng();
										//$(\"lat\"+sherhMap.id).attr(\"value\",pt.lat());
										//$(\"lng\"+sherhMap.id).attr(\"value\", pt.lng());
										sherhMap.resultCoord(pt.lat(),pt.lng(),pt);
										
									});
									GEvent.addListener(sherhMap.map[id], \"moveend\", function() {
										sherhMap.map[id].clearOverlays();
										sherhMap.center = sherhMap.map[id].getCenter();
										sherhMap.marker = new GMarker(sherhMap.center, {draggable: true});
										sherhMap.map[id].addOverlay(sherhMap.marker);
										var pt = sherhMap.marker.getPoint();
										sherhMap.resultCoord(sherhMap.center.lat(),sherhMap.center.lng(),pt);
					
										GEvent.addListener(sherhMap.marker, \"dragend\", function() {
											var pt = sherhMap.marker.getPoint();
											sherhMap.map[id].panTo(pt);
											//$(\"lat\"+sherhMap.obiekt).attr(\"value\",pt.lat());
											//$(\"lng\"+sherhMap.obiekt).attr(\"value\", pt.lng());
											document.getElementById(\"lat\"+sherhMap.obiekt).value = pt.lat();
											document.getElementById(\"lng\"+sherhMap.obiekt).value = pt.lng();
											sherhMap.resultCoord(pt.lat(),pt.lng(),pt);
											
										});
									});
								}
							});
						}
					}
				}
	
	$(document).ready(function() {
		sherhMap.init('-ID-'); // uruchomienie mapy	
		//sherhMap.showAddress('-ID-');
	});
	",$options = array('allowCache'=>true,'safe'=>true,'inline'=>false));
?>
<div class="input text required">
<input class="wybrane-adresy-lokali" type="text" id="tapAdres-ID-" name="tapAdres" value="<?php echo (isset($lacation)) ? $lacation : __('find on map...',true)?>"/> <input class="szukaj-na-mapie-wg-adresu" type="button" onclick="sherhMap.showAddress('-ID-'); return false" value="Find on Map"/>
</div>
<div id="map_-ID-" style="width: 300px; height: 300px; display: block; "> </div>

<input type="hidden" name="data[Destination][latitude]" id="lat-ID-" value="<?php echo $latitude ?>"/>
<input type="hidden" name="data[Destination][longitude]" id="lng-ID-" value="-<?php echo $longitude ?>"/>
<input type="text" name="data[Destination][gps]" id="gps-ID-" value="<?php echo $gps ?>" style="width: 300px;"/>